import * as cornerstoneTools from "@cornerstonejs/tools";
import { CrosshairsTool, PlanarRotateTool, StackScrollTool } from "@cornerstonejs/tools";
import { FOUR_CORNER, FOUR_CORNER_SHOW_NAME, DICOM_TAG_ATTR } from "./types";


const {
  PanTool,
  WindowLevelTool,
  ZoomTool,
  AngleTool,
  RectangleROITool,
  LengthTool,
  Enums: csToolsEnums
} = cornerstoneTools;
const { MouseBindings } = csToolsEnums;

const IMG_USER_OP_NAME = {
  None: "None",
  PAN: "PAN",
  ZOOM: "ZOOM",
  WINDOW: "WINDOW",
  ROTATE: "ROTATE",
  SCROLL: "SCROLL",
  CROSSHAIR: "CROSSHAIR",
  LENGTH: "LENGTH",
  ANGEL: "ANGEL",
  RECT: "RECT"
};

const IMG_OP_NOT_TOOL_NAME = {
  FLIP_H: "FLIP_H",
  FLIP_V: "FLIP_V",
  INVERT: "INVERT",
  COLOR_MAP: "COLOR_MAP"
};

const IMG_OP_NAME_RESET = {
  RESET_CAMERA: "RESET_CAMERA",
  RESET_PROPERTIES: "RESET_PROPERTIES",
  RESET_MEASURE: "RESET_MEASURE"
};

const IMG_OP_NAME = Object.assign({}, IMG_USER_OP_NAME, IMG_OP_NAME_RESET, IMG_OP_NOT_TOOL_NAME);


const FOUR_CORNER_SETTING = {
  [FOUR_CORNER.LT]: [FOUR_CORNER_SHOW_NAME.Manufacturer, FOUR_CORNER_SHOW_NAME.INDEX, FOUR_CORNER_SHOW_NAME.View_type, FOUR_CORNER_SHOW_NAME.Position],
  [FOUR_CORNER.LB]: [FOUR_CORNER_SHOW_NAME.KV, FOUR_CORNER_SHOW_NAME.MA, FOUR_CORNER_SHOW_NAME.SliceThickness, FOUR_CORNER_SHOW_NAME.WW, FOUR_CORNER_SHOW_NAME.WL],
  [FOUR_CORNER.RT]: [FOUR_CORNER_SHOW_NAME.InstitutionName, FOUR_CORNER_SHOW_NAME.PatientName, FOUR_CORNER_SHOW_NAME.PatientID, FOUR_CORNER_SHOW_NAME.PatientSex, FOUR_CORNER_SHOW_NAME.PatientAge],
  [FOUR_CORNER.RB]: [FOUR_CORNER_SHOW_NAME.X, FOUR_CORNER_SHOW_NAME.Y, FOUR_CORNER_SHOW_NAME.CT]
};

const DONT_SHOW_ATTR = [FOUR_CORNER_SHOW_NAME.View_type,
  FOUR_CORNER_SHOW_NAME.Position, FOUR_CORNER_SHOW_NAME.SliceThickness, FOUR_CORNER_SHOW_NAME.InstitutionName, FOUR_CORNER_SHOW_NAME.Manufacturer,
  FOUR_CORNER_SHOW_NAME.PatientName, FOUR_CORNER_SHOW_NAME.PatientID, FOUR_CORNER_SHOW_NAME.PatientSex, FOUR_CORNER_SHOW_NAME.PatientAge
];

const OP_TOOLS_MAP = {
  [IMG_OP_NAME.PAN]: {
    tool: PanTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.ZOOM]: {
    tool: ZoomTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        },
        { numTouchPoints: 2 }
      ]
    }
  },
  [IMG_OP_NAME.WINDOW]: {
    tool: WindowLevelTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.ROTATE]: {
    tool: PlanarRotateTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.SCROLL]: {
    tool: StackScrollTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.CROSSHAIR]: {
    tool: CrosshairsTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.LENGTH]: {
    tool: LengthTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.ANGEL]: {
    tool: AngleTool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  },
  [IMG_OP_NAME.RECT]: {
    tool: RectangleROITool,
    toolBindingsOptions: {
      bindings: [
        {
          mouseButton: MouseBindings.Primary // Left Click
        }
      ]
    }
  }
};

export {
  FOUR_CORNER_SHOW_NAME,
  FOUR_CORNER_SETTING,
  OP_TOOLS_MAP,
  DICOM_TAG_ATTR,
  IMG_OP_NAME,
  FOUR_CORNER,
  IMG_USER_OP_NAME,
  IMG_OP_NOT_TOOL_NAME,
  IMG_OP_NAME_RESET,
  DONT_SHOW_ATTR
};
